<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var prjId='${prjId}';
	var cstType='${cstType}';
	var cstId = '${cstId}';
	var cstRlCd = '${cstRlCd}';
	var otherGrid = null;
	var buildingGrid = null;
	var equipmentGrid = null;
	var detailFlag = '${detailFlag}';
	$(function () {
		initEquipmentGrid();//设备gird;
		initBuildingGrid();//房产grid
		initOtherGrid();//其他grid
		if(detailFlag=="true"){
			$("#equipmentAddBtn").hide();
			$("#equipmentRemoveBtn").hide();
			$("#buildingAddBtn").hide();
			$("#buildingRemoveBtn").hide();
			$("#otherAddBtn").hide();
			$("#otherRemoveBtn").hide();
		}
		
	});
	
	//初始化列表
	function initOtherGrid(){
		var params = {};
		params.assPropCd = ProjectConstant.CST_ASS_PROP_OTH_CD;
		params.prjId = prjId;
		params.cstId = cstId;
		params.cstRlCd = cstRlCd;
		$("#otherGrid").ligerGrid({
	    	url: '<%=path%>/project/prjcstassmbInfo/initPrjCstAssMbInfoList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	             { display: '资产名称', name: 'assNm', minWidth: 140 ,
	  	            	render: function (rowdata, rowindex, value, column) { 
	  	            		var h = '';
	  	            		    h='<a class="sq-button-hasicon" href="javascript:otherDetailBtn(';
	  	                        h+="'"+rowdata.id+"'";
	  	                        h+=')">'+value+'</a>'
	  	                        return h;
	  	            		},
	  	            	enabledSort:true},
	            { display: '购买时间', name: 'purchDt', minWidth: 100 ,render:renderDate,enabledSort:true},
	            { display: '现估价（万元）', name: 'value', minWidth: 140 , enabledSort:true},
	            { display: '财产状况', name: 'assSts', minWidth: 140 , enabledSort:true},
	            { display: '与申请人关系', name: 'assRlCdNm', minWidth: 60, enabledSort:true },
	            {
	                display: '操作',
	                isSort: false,
	                width: 100,
	                render: function (rowdata, rowindex, value){
	                	 var h="";
	                	 if(detailFlag!="true"){
	                        h='<a class="sq-button-hasicon" href="javascript:otherModifyBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')"><i class="sqBtnIco_4"></i>修改</a>'
	               		 }
	                    return h;
	                }
	            }
	        ],
	        pageSize:100,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        heightDiff:-2,
	        checkbox:true,
	        allowUnSelectRow: true,
            alternatingRow: false,
	        rownumbers:true,
	        usePagerOnLessPagesize: false,
	    });
		otherGrid = liger.get("otherGrid");
	}
	function initBuildingGrid(){
		var params = {};
		params.assPropCd = ProjectConstant.CST_ASS_PROP_BUIL_CD;
		params.prjId = prjId;
		params.cstId = cstId;
		params.cstRlCd = cstRlCd;
		$("#buildingGrid").ligerGrid({
	    	url: '<%=path%>/project/prjcstassmbInfo/initPrjCstAssMbInfoList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	                  { display: '房屋登记号', name: 'assNo', minWidth: 140 ,
		  	            	render: function (rowdata, rowindex, value, column) { 
		  	            		var h = '';
		  	            		    h='<a class="sq-button-hasicon" href="javascript:buildingDetailBtn(';
		  	                        h+="'"+rowdata.id+"'";
		  	                        h+=')">'+value+'</a>'
		  	                        return h;
		  	            		},
		  	            	enabledSort:true},
	            { display: '面积（平米）', name: 'area', minWidth: 60, enabledSort:true },
	            { display: '现估计（万元）', name: 'value', minWidth: 140 , enabledSort:true},
	            //{ display: '房屋登记号', name: 'assNo', minWidth: 140 , enabledSort:true},
	            { display: '所有权人', name: 'assOwner', width: 50,align:'left' , enabledSort:true},
	            { display: '与申请人关系', name: 'assRlCdNm', width: 50,align:'left' , enabledSort:true},
	            { display: '抵押状态', name: 'mStsCdNm', minWidth: 140 , enabledSort:true},
	            { display: '房屋地址', name: 'addr', minWidth: 140 , enabledSort:true},
	            { display: '权属性质', name: 'natureCdNm', minWidth: 140 , enabledSort:true},
	            {
	                display: '操作',
	                isSort: false,
	                width: 100,
	                render: function (rowdata, rowindex, value){
	                	 var h="";
	                	 if(detailFlag!="true"){
	                        h='<a class="sq-button-hasicon" href="javascript:buildingModifyBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')"><i class="sqBtnIco_4"></i>修改</a>'
	               		 }
	                    return h;
	                }
	            }
	        ],
	        pageSize:100,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        heightDiff:-2,
	        checkbox:true,
	        allowUnSelectRow: true,
            alternatingRow: false,
	        rownumbers:true,
	        usePagerOnLessPagesize: false,
	    });
		buildingGrid = liger.get("buildingGrid");
	}
	function initEquipmentGrid(){
		var params = {};
		params.assPropCd = ProjectConstant.CST_ASS_PROP_EQUI_CD;
		params.prjId = prjId;
		params.cstId = cstId;
		params.cstRlCd = cstRlCd;
		 var list =  getColumn(params.assPropCd,cstType);
		$("#equipmentGrid").ligerGrid({
	    	url: '<%=path%>/project/prjcstassmbInfo/initPrjCstAssMbInfoList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	                  { display: '设备名称', name: 'assNm', minWidth: 140 ,
		  	            	render: function (rowdata, rowindex, value, column) { 
		  	            		var h = '';
		  	            		    h='<a class="sq-button-hasicon" href="javascript:equipmentDetailBtn(';
		  	                        h+="'"+rowdata.id+"'";
		  	                        h+=')">'+value+'</a>'
		  	                        return h;
		  	            		},
		  	            	enabledSort:true},
	            { display: '买入价格', name: 'untPc', minWidth: 60, enabledSort:true },
	            { display: '购买时间', name: 'purchDt', minWidth: 140 ,render:renderDate, enabledSort:true},
	            { display: '所有权人', name: 'assOwner', minWidth: 140 , enabledSort:true},
	            { display: '于申请人关系', name: 'assRlCdNm', width: 50,align:'left' , enabledSort:true},
	            { display: '抵押状态', name: 'mStsCdNm', width: 50,align:'left' , enabledSort:true},
	            { display: '设备状况', name: 'assSts', minWidth: 140 , enabledSort:true},
	            { display: '品牌', name: 'brNm', minWidth: 140, enabledSort:true },
	            { display: '号牌', name: 'assNo', minWidth: 140, enabledSort:true },
	            {
	                display: '操作',
	                isSort: false,
	                width: 100,
	                render: function (rowdata, rowindex, value){
	                	 var h="";
	                	 if(detailFlag!="true"){
	                        h='<a class="sq-button-hasicon" href="javascript:equipmentModifyBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')"><i class="sqBtnIco_4"></i>修改</a>'
	               		 }
	                    return h;
	                }
	            }
	        ],
	        pageSize:100,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        heightDiff:-2,
	        checkbox:true,
	        allowUnSelectRow: true,
            alternatingRow: false,
	        rownumbers:true,
	        usePagerOnLessPagesize: false,
	    });
		equipmentGrid = liger.get("equipmentGrid");
	}
	
	
	function getColumn(cstAssProp,cstTyp){
		var column = [];
		if(cstAssProp==ProjectConstant.CST_ASS_PROP_EQUI_CD&&cstTyp==ProjectConstant.CST_TYP_CD_NP){
			column.push({ display: '设备名称', name: 'assNm', minWidth: 140, enabledSort:true });
		}
		if(cstAssProp==ProjectConstant.CST_ASS_PROP_EQUI_CD&&cstTyp==ProjectConstant.CST_TYP_CD_LP){
			column.push({ display: '品牌', name: 'brNm', minWidth: 140, enabledSort:true });
			column.push({ display: '号牌', name: 'assNo', minWidth: 140, enabledSort:true });
		}
		if(cstAssProp==ProjectConstant.CST_ASS_PROP_OTH_CD&&cstTyp==ProjectConstant.CST_TYP_CD_NP){
		//	column.push({ display: '资产类型', name: 'cstStsCdNm', minWidth: 60, enabledSort:true });
			column.push({ display: '与申请人关系', name: 'assRlCdNm', minWidth: 60, enabledSort:true });
		}
			
		return column;
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value&&value!=''){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	//添加设备
	function equipmentAddBtn(){
  		var win = $.ligerDialog.open({title:"添加设备资产信息", height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toEquiAddPage.do?cstType='+cstType+'&&cstId='+cstId+'&&prjId='+prjId+'&&cstRlCd='+cstRlCd, isResize: true });
	}
	//添加房产
	function buildingAddBtn(){
  		var win = $.ligerDialog.open({  title:"添加房产资产信息",height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toBuilAddPage.do?cstType='+cstType+'&&cstId='+cstId+'&&prjId='+prjId+'&&cstRlCd='+cstRlCd, isResize: true });
	}
	//添加其他
	function otherAddBtn(){
  		var win = $.ligerDialog.open({ title:"添加其他设备资产信息", height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toOthAddPage.do?cstType='+cstType+'&&cstId='+cstId+'&&prjId='+prjId+'&&cstRlCd='+cstRlCd, isResize: true });
	}

	//修改设备
	function equipmentModifyBtn(id){
  		var win = $.ligerDialog.open({ title:"修改设备资产信息",height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toEquiModifyPage.do?id='+id+'&&cstId='+cstId+'&&prjId='+prjId+'&&cstRlCd='+cstRlCd, isResize: true });
	}
	//修改房产
	function buildingModifyBtn(id){
  		var win = $.ligerDialog.open({ title:"修改房产资产信息",height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toBuilModifyPage.do?id='+id+'&&cstId='+cstId+'&&prjId='+prjId+'&&cstRlCd='+cstRlCd, isResize: true });
	}
	//修改其他
	function otherModifyBtn(id){
  		var win = $.ligerDialog.open({  title:"修改其他设备资产信息",height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toOthModifyPage.do?id='+id+'&&cstId='+cstId+'&&prjId='+prjId+'&&cstRlCd='+cstRlCd, isResize: true });
	}
	
	//查看设备
	function equipmentDetailBtn(id){
  		var win = $.ligerDialog.open({ title:"查看设备资产信息",height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toEquiDetailPage.do?id='+id+'&&cstId='+cstId+'&&prjId='+prjId, isResize: true });
	}
	//查看房产
	function buildingDetailBtn(id){
  		var win = $.ligerDialog.open({ title:"查看房产资产信息",height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toBuilDetailPage.do?id='+id+'&&cstId='+cstId+'&&prjId='+prjId, isResize: true });
	}
	//查看其他
	function otherDetailBtn(id){
	/* 	var selectedRows = otherGrid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var id = selectedRows[0].id; */
  		var win = $.ligerDialog.open({title:"查看其他资产信息", height: 300,width: 800, url: '<%=path%>/project/prjcstassmbInfo/toOthDetailPage.do?id='+id+'&&cstId='+cstId+'&&prjId='+prjId, isResize: true });
	}
	
	
	//删除其他
	function otherRemoveBtn(){
		removeBtn(otherGrid);
	}
	//删除设备
	function equipmentRemoveBtn(){
		removeBtn(equipmentGrid);
	}
	//删除房产
	function buildingRemoveBtn(){
		removeBtn(buildingGrid);
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//删除所选客户资产抵押信息
	function removeBtn(grid){
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		}
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjcstassmbInfo/removeByIds.do',
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
		
	}
	//保存所选项目抵押信息
	function addSelect(){
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var prjCstBscInfoList = [];
		for ( var index in selectedRows) {
			var obj = {};
			obj.cstId =selectedRows[index].cstId; 
			obj.prjId =prjId; 
			obj.cstRlCd =ProjectConstant.CST_RL_SPONSOR; 
			obj.guarTypCd =selectedRows[index].guarTypCdId;
			obj.guarAmt  =selectedRows[index].guarAmt;
			obj.cstTypCd = selectedRows[index].cstTypCd;
			prjCstBscInfoList.push(obj);
		}
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{prjCstBscInfo:JSON.stringify(prjCstBscInfoList)},
				url: '<%=path%>/project/prjcstbscInfo/addSelectPrjCstBscInfo.do',
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
	}
</script>

<body class="iframeBody">
	<div class="Wrapper">
	 <div class="pageIn2layout">
	<jsp:include page="../../project/prjbscinfo/prjInvestRpt.jsp" flush="true" >
			<jsp:param name="currentNav" value="prjCstAssMbInfo"/>
	</jsp:include>
	<div class="pageIn2L_mid">
    <div id="pageInTab" class="pageInTab">
    <div class="clearFix"></div>
<div class="btnsBox">
         <span id="equipmentAddBtn" onclick="equipmentAddBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->新增</span>
 	     <span id="equipmentRemoveBtn" onclick="equipmentRemoveBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_7"></i> -->作废</span>
 	     <!-- <span id="modifyBtn" onclick="equipmentModifyBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_4"></i>修改</span>
 	     <span id="detailBtn" onclick="equipmentDetailBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>详细</span> -->
  </div>
<div id="equipmentGrid" class="sq-grid"></div>
<div class="clearFix"></div>
<div class="btnsBox">
         <span id="buildingAddBtn" onclick="buildingAddBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->新增</span>
 		<span id="buildingRemoveBtn" onclick="buildingRemoveBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_7"></i> -->作废</span>
 	<!--      <span id="modifyBtn" onclick="buildingModifyBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_4"></i>修改</span>
 	     <span id="detailBtn" onclick="buildingDetailBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>详细</span> -->
  </div>
<div id="buildingGrid" class="sq-grid"></div>
<div class="clearFix"></div>
<div class="btnsBox">
         <span id="otherAddBtn" onclick="otherAddBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->新增</span>
  		 <span id="otherRemoveBtn" onclick="otherRemoveBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_7"></i> -->作废</span>
      <!--  <span id="modifyBtn" onclick="otherModifyBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_4"></i>修改</span>
        <span id="detailBtn" onclick="otherDetailBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>详细</span> -->
  </div>
<div id="otherGrid" class="sq-grid"></div>
</div>
	</div>
	</div>
	</div>
</body>
</html>